import { Mock } from "mockjs";

// 模拟系统统计数据
const systemStats = {
  totalUsers: 1250,
  totalOrders: 3680,
  totalRevenue: 125680,
  totalProducts: 89,
};

// 模拟图表数据
const chartData = {
  // 用户增长趋势
  userGrowth: [
    { month: "1月", users: 120 },
    { month: "2月", users: 150 },
    { month: "3月", users: 180 },
    { month: "4月", users: 220 },
    { month: "5月", users: 280 },
    { month: "6月", users: 320 },
  ],

  // 销售数据
  salesData: [
    { name: "电子产品", value: 35 },
    { name: "服装", value: 25 },
    { name: "食品", value: 20 },
    { name: "图书", value: 15 },
    { name: "其他", value: 5 },
  ],

  // 订单状态分布
  orderStatus: [
    { status: "待支付", count: 45 },
    { status: "已支付", count: 120 },
    { status: "配送中", count: 80 },
    { status: "已完成", count: 200 },
    { status: "已取消", count: 15 },
  ],
};

// 模拟通知数据
const notifications = [
  {
    id: 1,
    title: "系统维护通知",
    content: "系统将于今晚22:00-24:00进行维护升级",
    type: "warning",
    time: "2024-01-15 10:30:00",
    isRead: false,
  },
  {
    id: 2,
    title: "新用户注册",
    content: "用户 '张三' 刚刚注册了账号",
    type: "info",
    time: "2024-01-15 09:15:00",
    isRead: true,
  },
  {
    id: 3,
    title: "订单异常",
    content: "订单 #12345 支付状态异常，请及时处理",
    type: "error",
    time: "2024-01-15 08:45:00",
    isRead: false,
  },
];

export default [
  // 获取系统统计数据
  {
    url: "/api/system/stats",
    method: "get",
    response: () => {
      return {
        code: 1,
        message: "获取统计数据成功",
        data: systemStats,
      };
    },
  },

  // 获取图表数据
  {
    url: "/api/charts/userGrowth",
    method: "get",
    response: () => {
      return {
        code: 1,
        message: "获取用户增长数据成功",
        data: chartData.userGrowth,
      };
    },
  },

  {
    url: "/api/charts/salesData",
    method: "get",
    response: () => {
      return {
        code: 1,
        message: "获取销售数据成功",
        data: chartData.salesData,
      };
    },
  },

  {
    url: "/api/charts/orderStatus",
    method: "get",
    response: () => {
      return {
        code: 1,
        message: "获取订单状态数据成功",
        data: chartData.orderStatus,
      };
    },
  },

  // 获取通知列表
  {
    url: "/api/notifications",
    method: "get",
    response: () => {
      return {
        code: 1,
        message: "获取通知列表成功",
        data: {
          list: notifications,
          total: notifications.length,
          unreadCount: notifications.filter((n) => !n.isRead).length,
        },
      };
    },
  },

  // 标记通知为已读
  {
    url: "/api/notifications/:id/read",
    method: "put",
    response: ({ query }) => {
      const notificationId = parseInt(query.id);
      const notification = notifications.find((n) => n.id === notificationId);

      if (notification) {
        notification.isRead = true;
        return {
          code: 1,
          message: "标记通知已读成功",
          data: null,
        };
      } else {
        return {
          code: 0,
          message: "通知不存在",
          data: null,
        };
      }
    },
  },

  // 获取系统配置
  {
    url: "/api/system/config",
    method: "get",
    response: () => {
      return {
        code: 1,
        message: "获取系统配置成功",
        data: {
          siteName: "Vue Admin 管理系统",
          siteLogo: "/logo.png",
          theme: "light",
          language: "zh-CN",
          timezone: "Asia/Shanghai",
        },
      };
    },
  },
];
